'
' DotNetNuke -  http://www.dotnetnuke.com
' Copyright (c) 2002-2005
' by Shaun Walker ( sales@perpetualmotion.ca ) of Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
'
Imports DotNetNuke
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Common.Globals
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Modules

Namespace DotNetNuke.Modules.ProjectTracker

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' The Editdnn_PT_StateSubscribers PortalModuleBase is used to manage dnn_PT_StateSubscribers
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public MustInherit Class EMailEdit
        Inherits Entities.Modules.PortalModuleBase

#Region "Controls"

        Protected WithEvents fldEMail As System.Web.UI.WebControls.TextBox  ' nvarchar

        'tasks
        Protected WithEvents cmdUpdate As System.Web.UI.WebControls.LinkButton
        Protected WithEvents cmdCancel As System.Web.UI.WebControls.LinkButton
        Protected WithEvents cmdDelete As System.Web.UI.WebControls.LinkButton

        ' footer
        Protected WithEvents ctlAudit As UI.UserControls.ModuleAuditControl

#End Region

#Region "Private Members"

        Private m_itemId As Integer = -1
        Private m_stateId As Integer = -1
        Private m_typeId As Integer = -1
        Private m_moduleId As Integer = -1

        Private m_StateSubscribersController As New StateSubscribersController
        Private m_StateSubscribersInfo As StateSubscribersInfo

#End Region

#Region "Event Handlers"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Page_Load runs when the control is loaded
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                ' Determine ItemId of dnn_PT_StateSubscribers to Update
                If Not (Request.QueryString("ItemId") Is Nothing) Then
                    m_itemId = Int32.Parse(Request.QueryString("ItemId"))
                End If

                ' Determine stateId
                If Not (Request.Params("StateId") Is Nothing) Then
                    m_stateId = Int32.Parse(Request.Params("StateId"))
                End If

                If Not (Request.QueryString("TypeID") Is Nothing) Then
                    m_typeId = Int32.Parse(Request.QueryString("TypeId"))
                End If

                ' /// Determine ModuleId
                m_moduleId = Int32.Parse(Request.Params("Mid"))

                ' If the page is being requested the first time, determine if an
                ' dnn_PT_StateSubscribers itemId value is specified, and if so populate page
                ' contents with the dnn_PT_StateSubscribers details
                If Page.IsPostBack = False Then

                    cmdDelete.Attributes.Add("onClick", "javascript:return confirm('" & Localization.GetString("DeleteItem") & "');")

                    If m_itemId <> -1 Then
                        ' Obtain a single row of dnn_PT_StateSubscribers information
                        ' /// Retrieve the requested Item using the ItemId
                        m_StateSubscribersInfo = m_StateSubscribersController.GetStateSubscribersInfo(m_itemId)

                        If Not m_StateSubscribersInfo Is Nothing Then
                            fldEMail.Text = m_StateSubscribersInfo.EMail.ToString()
                            ctlAudit.CreatedDate = m_StateSubscribersInfo.CreatedDate.ToString
                            ctlAudit.CreatedByUser = m_StateSubscribersInfo.CreatedByUser.ToString

                            m_stateId = m_StateSubscribersInfo.StateID
                            m_typeId = m_StateSubscribersInfo.SubscriptionType

                        Else       ' security violation attempt to access item not related to this Module

                            Response.Redirect(NavigateURL(), True)
                        End If
                    Else
                        cmdDelete.Visible = False
                        ctlAudit.Visible = False
                    End If

                End If
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' cmdCancel_Click runs when the cancel button is clicked
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub cmdCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdCancel.Click
            Try
                Response.Redirect(EditUrl("ItemID", m_stateId.ToString(), "EditStates", ""))
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' cmdDelete_Click runs when the delete button is clicked
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub cmdDelete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdDelete.Click
            Try
                If m_itemId <> -1 Then
                    m_StateSubscribersController.DeleteStateSubscribers(m_itemId)
                End If

                ' Redirect back to the portal home page
                Response.Redirect(EditUrl("ItemID", m_stateId.ToString(), "EditStates", ""))
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' cmdUpdate_Click runs when the update button is clicked
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdUpdate.Click
            Try
                ' Only Update if Entered data is Valid
                If Page.IsValid = True Then

                    ' /// Create an instance of the Event DB component

                    ' /// if ItemId is 0 then we're adding a new item, otherwise we're updating an existing item
                    If m_itemId = -1 Then
                        m_StateSubscribersInfo = New StateSubscribersInfo
                        m_StateSubscribersInfo.ItemID = m_itemId
                        m_StateSubscribersInfo.ModuleID = m_moduleId
                        m_StateSubscribersInfo.CreatedByUser = UserInfo.UserID
                        m_StateSubscribersInfo.CreatedDate = Date.Now()
                        m_StateSubscribersInfo.EMail = fldEMail.Text.Trim()
                        m_StateSubscribersInfo.StateID = m_stateId
                        m_StateSubscribersInfo.SubscriptionType = m_typeId
                        m_StateSubscribersController.AddStateSubscribers(m_StateSubscribersInfo)
                    Else
                        m_StateSubscribersInfo = m_StateSubscribersController.GetStateSubscribersInfo(m_itemId)
                        m_StateSubscribersInfo.CreatedByUser = UserInfo.UserID
                        m_StateSubscribersInfo.CreatedDate = Date.Now()
                        m_StateSubscribersInfo.EMail = fldEMail.Text.Trim()
                        m_StateSubscribersController.UpdateStateSubscribers(m_StateSubscribersInfo)
                    End If

                    ' Redirect back to the portal home page
                    Response.Redirect(EditUrl("ItemID", m_StateSubscribersInfo.StateID.ToString(), "EditStates", ""))

                End If
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

#End Region

#Region " Web Form Designer Generated Code "

        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        End Sub

        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
            InitializeComponent()
        End Sub

#End Region

    End Class

End Namespace
